package com.mytest.leetcode;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Solution383 {

    public static void main(String[] args) {
        Solution383 solution704 = new Solution383();
        log.info("{}", solution704.canConstruct("aabb",""));
    }


    public boolean canConstruct(String ransomNote, String magazine) {
        if (ransomNote.length() > magazine.length()) {
            return false;
        }
        int[] cnt = new int[26];
        for (char c : magazine.toCharArray()) {
            cnt[c - 'a']++;
        }
        for (char c : ransomNote.toCharArray()) {
            cnt[c - 'a']--;
            if(cnt[c - 'a'] < 0) {
                return false;
            }
        }
        return true;
    }
}
